

package com.hazelcast.config.security;

import com.hazelcast.security.Credentials;
import com.hazelcast.security.ICredentialsFactory;

import javax.security.auth.callback.CallbackHandler;

import static java.util.Objects.requireNonNull;

/**
 * The credentials factory implementation which just takes credentials in a constructor and provides it for every
 * {@link #newCredentials()} call.
 */
public class StaticCredentialsFactory implements ICredentialsFactory {

    private Credentials credentials;

    public StaticCredentialsFactory(Credentials credentials) {
        this.credentials = requireNonNull(credentials, "Credentials have to be provided");
    }

    @Override
    public void configure(CallbackHandler callbackHandler) {
    }

    @Override
    public Credentials newCredentials() {
        return credentials;
    }

    @Override
    public void destroy() {
        credentials = null;
    }

}
